home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / gepackte_disketten / 1994 / 08_94_5.dms / 08_94_5.adf / term-4.0-Source.lha / termPrint.c < prev    next >
C/C++ Source or Header  |  1994-06-20  |  19KB  |  912 lines

  1. /*
  2. **    termPrint.c
  3. **
  4. **    Printer control routines
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...):
  13.      *
  14.      *    Output a printf() style message.
  15.      */
  16.  
  17. BYTE __stdargs
  18. PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...)
  19. {
  20.     va_list    VarArgs;
  21.     LONG    Len;
  22.  
  23.     va_start(VarArgs,String);
  24.     VSPrintf(SharedBuffer,String,VarArgs);
  25.     va_end(VarArgs);
  26.  
  27.     if(ReqWindow)
  28.     {
  29.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  30.         {
  31.             *Error = 0;
  32.  
  33.             return(FALSE);
  34.         }
  35.     }
  36.     else
  37.     {
  38.         if(CheckSignal(SIG_BREAK))
  39.         {
  40.             *Error = 0;
  41.  
  42.             return(FALSE);
  43.         }
  44.     }
  45.  
  46.     Len = strlen(SharedBuffer) + 1;
  47.  
  48.     SetIoErr(0);
  49.  
  50.     if(FPrintf(File,"%s\n",SharedBuffer) < Len)
  51.     {
  52.         *Error = IoErr();
  53.  
  54.         return(FALSE);
  55.     }
  56.     else
  57.         return(TRUE);
  58. }
  59.  
  60.     /* PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code):
  61.      *
  62.      *    Print a line header.
  63.      */
  64.  
  65. STATIC BYTE __regargs
  66. PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code,BYTE Plain)
  67. {
  68.     STRPTR    String;
  69.     LONG    Len;
  70.  
  71.     String = LocaleString(Code);
  72.     Len = strlen(String);
  73.  
  74.     if(ReqWindow)
  75.     {
  76.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  77.         {
  78.             *Error = 0;
  79.  
  80.             return(FALSE);
  81.         }
  82.     }
  83.     else
  84.     {
  85.         if(CheckSignal(SIG_BREAK))
  86.         {
  87.             *Error = 0;
  88.  
  89.             return(FALSE);
  90.         }
  91.     }
  92.  
  93.     if(!Plain)
  94.     {
  95.         SetIoErr(0);
  96.  
  97.         if(FWrite(File,"\33[1m",4,1) < 1)
  98.         {
  99.             *Error = IoErr();
  100.  
  101.             return(FALSE);
  102.         }
  103.     }
  104.  
  105.     SetIoErr(0);
  106.  
  107.     if(FWrite(File,String,Len,1) < 1)
  108.     {
  109.         *Error = IoErr();
  110.  
  111.         return(FALSE);
  112.     }
  113.  
  114.     if(!Plain)
  115.     {
  116.         SetIoErr(0);
  117.  
  118.         if(FWrite(File,"\33[0m",4,1) < 1)
  119.         {
  120.             *Error = IoErr();
  121.  
  122.             return(FALSE);
  123.         }
  124.     }
  125.  
  126.     return(TRUE);
  127. }
  128.  
  129.     /* PrintFileInformation():
  130.      *
  131.      *    Print information on a file.
  132.      */
  133.  
  134. BYTE __regargs
  135. PrintFileInformation(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR Name,ULONG Flags)
  136. {
  137.     BYTE Continue;
  138.  
  139.         /* Any special information to print along with the name? */
  140.  
  141.     if(Flags)
  142.     {
  143.         BPTR FileLock;
  144.  
  145.             /* Try to grip the file. */
  146.  
  147.         if(FileLock = Lock(Name,ACCESS_READ))
  148.         {
  149.             struct FileInfoBlock *FileInfo;
  150.  
  151.                 /* Allocate info buffer. */
  152.  
  153.             if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  154.             {
  155.                     /* How does it look like? */
  156.  
  157.                 if(Examine(FileLock,FileInfo))
  158.                 {
  159.                     UBYTE    DummyBuffer[300];
  160.                     STRPTR    Index;
  161.  
  162.                         /* Add the size. */
  163.  
  164.                     if(Flags & PRINT_SIZE)
  165.                         SPrintf(DummyBuffer,"%-25s %7ld",FilePart(Name),FileInfo -> fib_Size);
  166.                     else
  167.                         SPrintf(DummyBuffer,"%-25s",FilePart(Name));
  168.  
  169.                     Index = DummyBuffer;
  170.  
  171.                         /* Find the end of the string. */
  172.  
  173.                     while(*Index)
  174.                         Index++;
  175.  
  176.                         /* Add the protection bits. */
  177.  
  178.                     if(Flags & PRINT_BITS)
  179.                     {
  180.                         STATIC STRPTR    SetBits = "----aps",
  181.                                 ClrBits = "dewr---";
  182.  
  183.                         UBYTE TempString[10];
  184.  
  185.                         WORD i;
  186.  
  187.                         strcpy(TempString," -------");
  188.  
  189.                         for(i = 0 ; i < 7 ; i++)
  190.                         {
  191.                             if(FileInfo -> fib_Protection & (1L << i))
  192.                                 TempString[6 - i + 1] = SetBits[i]; 
  193.                             else
  194.                                 TempString[6 - i + 1] = ClrBits[i]; 
  195.                         }
  196.  
  197.                         strcpy(Index,TempString);
  198.  
  199.                         while(*Index)
  200.                             Index++;
  201.                     }
  202.  
  203.                         /* Add the creation date. */
  204.  
  205.                     if(Flags & PRINT_DATE)
  206.                     {
  207.                         UBYTE        Date[20],
  208.                                 Time[20];
  209.                         struct DateTime    DateTime;
  210.  
  211.                             /* Prepare for date conversion. */
  212.  
  213.                         DateTime . dat_Stamp    = FileInfo -> fib_Date;
  214.                         DateTime . dat_Format    = FORMAT_DOS;
  215.                         DateTime . dat_Flags    = DTF_SUBST;
  216.                         DateTime . dat_StrDay    = NULL;
  217.                         DateTime . dat_StrDate    = Date;
  218.                         DateTime . dat_StrTime    = Time;
  219.  
  220.                             /* Convert the date. */
  221.  
  222.                         if(DateToStr(&DateTime))
  223.                         {
  224.                             SPrintf(Index," %-9s %s",Date,Time);
  225.  
  226.                             while(*Index)
  227.                                 Index++;
  228.                         }
  229.                     }
  230.  
  231.                         /* Add the file comment. */
  232.  
  233.                     if(Flags & PRINT_COMMENT)
  234.                         SPrintf(Index,"\n: %s",FileInfo -> fib_Comment);
  235.  
  236.                     Continue = PrintText(File,ReqWindow,Error,"%s\n",DummyBuffer);
  237.                 }
  238.                 else
  239.                     Continue = FALSE;
  240.  
  241.                 FreeDosObject(DOS_FIB,FileInfo);
  242.             }
  243.             else
  244.                 Continue = FALSE;
  245.  
  246.             UnLock(FileLock);
  247.         }
  248.         else
  249.             Continue = FALSE;
  250.     }
  251.     else
  252.         Continue = PrintText(File,ReqWindow,Error,"%s\n",Name);
  253.  
  254.     return(Continue);
  255. }
  256.  
  257.     /* PrintEntry(BPTR File,struct Window *ReqWindow,LONG *Error,struct PhoneEntry *Entry):
  258.      *
  259.      *    Print information on the contents of a phonebook entry.
  260.      */
  261.  
  262. BYTE __regargs
  263. PrintEntry(BPTR File,struct Window *ReqWindow,BYTE Plain,LONG *Error,struct PhoneEntry *Entry,ULONG Flags)
  264. {
  265.     if(Plain)
  266.     {
  267.         if(!PrintText(File,ReqWindow,Error,"\n\"%s\" (%s)",Entry -> Header -> Name,Entry -> Header -> Number))
  268.             return(FALSE);
  269.     }
  270.     else
  271.     {
  272.         if(!PrintText(File,ReqWindow,Error,"\n\33[4m\"%s\" (%s)\33[0m",Entry -> Header -> Name,Entry -> Header -> Number))
  273.             return(FALSE);
  274.     }
  275.  
  276.     if(Flags & PRINT_COMMENT)
  277.     {
  278.         if(Entry -> Header -> Comment[0])
  279.         {
  280.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COMMENT_TXT,Plain))
  281.                 return(FALSE);
  282.  
  283.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> Comment))
  284.                 return(FALSE);
  285.         }
  286.     }
  287.  
  288.     if(Flags & PRINT_USERNAME)
  289.     {
  290.         if(Entry -> Header -> UserName[0])
  291.         {
  292.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_USER_NAME_TXT,Plain))
  293.                 return(FALSE);
  294.  
  295.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> UserName))
  296.                 return(FALSE);
  297.         }
  298.     }
  299.  
  300.     if((Flags & PRINT_SERIAL) && Entry -> Config -> SerialConfig)
  301.     {
  302.         STATIC UBYTE Parities[] =
  303.         {
  304.             'N','E','O','M','S'
  305.         };
  306.  
  307.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_BAUD_RATE_TXT,Plain))
  308.             return(FALSE);
  309.  
  310.         if(LocaleBase)
  311.         {
  312.             if(!PrintText(File,ReqWindow,Error,"%lD",Entry -> Config -> SerialConfig -> BaudRate))
  313.                 return(FALSE);
  314.         }
  315.         else
  316.         {
  317.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> SerialConfig -> BaudRate))
  318.                 return(FALSE);
  319.         }
  320.  
  321.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_PARAMETERS_TXT,Plain))
  322.             return(FALSE);
  323.  
  324.         if(!PrintText(File,ReqWindow,Error,"%ld-%lc-%ld",Entry -> Config -> SerialConfig -> BitsPerChar,Parities[Entry -> Config -> SerialConfig -> Parity],Entry -> Config -> SerialConfig -> StopBits))
  325.             return(FALSE);
  326.  
  327.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANDSHAKING_TXT,Plain))
  328.             return(FALSE);
  329.  
  330.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_HANDSHAKING_NONE_TXT + Entry -> Config -> SerialConfig -> HandshakingProtocol)))
  331.             return(FALSE);
  332.  
  333.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DUPLEX_TXT,Plain))
  334.             return(FALSE);
  335.  
  336.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_DUPLEX_FULL_TXT + Entry -> Config -> SerialConfig -> Duplex)))
  337.             return(FALSE);
  338.  
  339.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_STRIP_BIT_TXT,Plain))
  340.             return(FALSE);
  341.  
  342.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> StripBit8)))
  343.             return(FALSE);
  344.  
  345.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FLOW_CONTROL_TXT,Plain))
  346.             return(FALSE);
  347.  
  348.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> xONxOFF)))
  349.             return(FALSE);
  350.  
  351.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_SERIAL_DRIVER_TXT,Plain))
  352.             return(FALSE);
  353.  
  354.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_NAME_UNIT_TEMPLATE_TXT),Entry -> Config -> SerialConfig -> SerialDevice, + Entry -> Config -> SerialConfig -> UnitNumber))
  355.             return(FALSE);
  356.     }
  357.  
  358.     if((Flags & PRINT_MODEM) && Entry -> Config -> ModemConfig)
  359.     {
  360.         if(Entry -> Config -> ModemConfig -> ModemInit[0])
  361.         {
  362.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_INIT_TXT,Plain))
  363.                 return(FALSE);
  364.  
  365.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemInit))
  366.                 return(FALSE);
  367.         }
  368.  
  369.         if(Entry -> Config -> ModemConfig -> ModemExit[0])
  370.         {
  371.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_EXIT_TXT,Plain))
  372.                 return(FALSE);
  373.  
  374.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemExit))
  375.                 return(FALSE);
  376.         }
  377.  
  378.         if(Entry -> Config -> ModemConfig -> ModemHangup[0])
  379.         {
  380.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANG_UP_TXT,Plain))
  381.                 return(FALSE);
  382.  
  383.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemHangup))
  384.                 return(FALSE);
  385.         }
  386.  
  387.         if(Entry -> Config -> ModemConfig -> DialPrefix[0])
  388.         {
  389.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_PREFIX_TXT,Plain))
  390.                 return(FALSE);
  391.  
  392.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialPrefix))
  393.                 return(FALSE);
  394.         }
  395.  
  396.         if(Entry -> Config -> ModemConfig -> DialSuffix[0])
  397.         {
  398.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_SUFFIX_TXT,Plain))
  399.                 return(FALSE);
  400.  
  401.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialSuffix))
  402.                 return(FALSE);
  403.         }
  404.  
  405.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_REDIAL_DELAY_TXT,Plain))
  406.             return(FALSE);
  407.  
  408.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> RedialDelay / 6,(Entry -> Config -> ModemConfig -> RedialDelay % 6) * 10))
  409.             return(FALSE);
  410.  
  411.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_TIMEOUT_TXT,Plain))
  412.             return(FALSE);
  413.  
  414.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> DialTimeout / 60,Entry -> Config -> ModemConfig -> DialTimeout % 60))
  415.             return(FALSE);
  416.  
  417.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_AUTO_BAUD_TXT,Plain))
  418.             return(FALSE);
  419.  
  420.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> ConnectAutoBaud)))
  421.             return(FALSE);
  422.  
  423.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DROP_DTR_TXT,Plain))
  424.             return(FALSE);
  425.  
  426.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> DropDTR)))
  427.             return(FALSE);
  428.     }
  429.  
  430.     if((Flags & PRINT_SCREEN) && Entry -> Config -> ScreenConfig)
  431.     {
  432.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DISPLAY_MODE_TXT,Plain))
  433.             return(FALSE);
  434.  
  435.         if(!PrintText(File,ReqWindow,Error,GetModeName(Entry -> Config -> ScreenConfig -> DisplayMode)))
  436.             return(FALSE);
  437.  
  438.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COLOUR_MODE_TXT,Plain))
  439.             return(FALSE);
  440.  
  441.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SCREENPANEL_COLOUR_AMIGA_TXT + Entry -> Config -> ScreenConfig -> ColourMode)))
  442.             return(FALSE);
  443.     }
  444.  
  445.     if((Flags & PRINT_TERMINAL) && Entry -> Config -> TerminalConfig)
  446.     {
  447.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TERMINAL_EMULATION_TXT,Plain))
  448.             return(FALSE);
  449.  
  450.         if(Entry -> Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  451.         {
  452.             if(!PrintText(File,ReqWindow,Error,"%s, \"%s\"",LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode),Entry -> Config -> TerminalConfig -> EmulationMode))
  453.                 return(FALSE);
  454.         }
  455.         else
  456.         {
  457.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode)))
  458.                 return(FALSE);
  459.         }
  460.  
  461.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FONT_TXT,Plain))
  462.             return(FALSE);
  463.  
  464.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_FONT_STANDARD_TXT + Entry -> Config -> TerminalConfig -> FontMode)))
  465.             return(FALSE);
  466.  
  467.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_COLUMNS_TXT,Plain))
  468.             return(FALSE);
  469.  
  470.         if(Entry -> Config -> TerminalConfig -> NumColumns < 20)
  471.         {
  472.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  473.                 return(FALSE);
  474.         }
  475.         else
  476.         {
  477.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumColumns))
  478.                 return(FALSE);
  479.         }
  480.  
  481.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_LINES_TXT,Plain))
  482.             return(FALSE);
  483.  
  484.         if(Entry -> Config -> TerminalConfig -> NumLines < 20)
  485.         {
  486.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  487.                 return(FALSE);
  488.         }
  489.         else
  490.         {
  491.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumLines))
  492.                 return(FALSE);
  493.         }
  494.  
  495.         if(Entry -> Config -> TerminalConfig -> KeyMapFileName[0])
  496.         {
  497.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_KEYMAP_FILE_TXT,Plain))
  498.                 return(FALSE);
  499.  
  500.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> TerminalConfig -> KeyMapFileName))
  501.                 return(FALSE);
  502.         }
  503.     }
  504.  
  505.     return(TRUE);
  506. }
  507.  
  508.     /* PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error):
  509.      *
  510.      *    Print the contents of the screen, requires the raster
  511.      *    to be available.
  512.      */
  513.  
  514. BYTE __regargs
  515. PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error)
  516. {
  517.     WORD     i,j;
  518.     UBYTE    *Buffer;
  519.  
  520.         /* Run down the lines... */
  521.  
  522.     for(i = 0 ; i <= LastLine ; i++)
  523.     {
  524.             /* Grab the line. */
  525.  
  526.         Buffer = &Raster[i * RasterWidth];
  527.  
  528.         j = LastColumn;
  529.  
  530.             /* Strip trailing spaces. */
  531.  
  532.         while(j >= 0 && Buffer[j] == ' ')
  533.             j--;
  534.  
  535.             /* Blank line? */
  536.  
  537.         if(j >= 0)
  538.         {
  539.             SetIoErr(0);
  540.  
  541.             if(!FWrite(File,Buffer,j + 1,1))
  542.             {
  543.                 *Error = IoErr();
  544.  
  545.                 return(FALSE);
  546.             }
  547.         }
  548.  
  549.             /* Is printing to be aborted? */
  550.  
  551.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  552.         {
  553.             *Error = 0;
  554.  
  555.             return(FALSE);
  556.         }
  557.  
  558.             /* Add line terminator. */
  559.  
  560.         SetIoErr(0);
  561.  
  562.         if(!FWrite(File,"\n",1,1))
  563.         {
  564.             *Error = IoErr();
  565.  
  566.             return(FALSE);
  567.         }
  568.  
  569.             /* Is printing to be aborted? */
  570.  
  571.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  572.         {
  573.             *Error = 0;
  574.  
  575.             return(FALSE);
  576.         }
  577.     }
  578.  
  579.     return(TRUE);
  580. }
  581.  
  582.     /* PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error):
  583.      *
  584.      *    Print the contents of the clipboard.
  585.      */
  586.  
  587. BYTE __regargs
  588. PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error)
  589. {
  590.     LONG ClipError;
  591.  
  592.         /* Are we currently reading input from the
  593.          * clipboard? If so, close it.
  594.          */
  595.  
  596.     if(ClipInput)
  597.     {
  598.         CloseClip();
  599.  
  600.         ClipInput = ClipXerox = FALSE;
  601.     }
  602.  
  603.         /* Open the clipboard for reading. */
  604.  
  605.     if(ClipError = OpenClip(Config -> ClipConfig -> ClipboardUnit))
  606.     {
  607.         *Error = ERROR_OBJECT_NOT_FOUND;
  608.  
  609.         return(FALSE);
  610.     }
  611.     else
  612.     {
  613.         UBYTE    InputBuffer[257];
  614.         WORD    Len;
  615.  
  616.             /* Read clipboard contents. */
  617.  
  618.         while((Len = GetClip(InputBuffer,256,TRUE)) > 0)
  619.         {
  620.                 /* Are we to stop printing? */
  621.  
  622.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  623.             {
  624.                 *Error = 0;
  625.  
  626.                 CloseClip();
  627.  
  628.                 return(FALSE);
  629.             }
  630.             else
  631.             {
  632.                 SetIoErr(0);
  633.  
  634.                 if(FWrite(File,InputBuffer,Len,1) < 1)
  635.                 {
  636.                     *Error = IoErr();
  637.  
  638.                     CloseClip();
  639.  
  640.                     return(FALSE);
  641.                 }
  642.             }
  643.         }
  644.  
  645.         if(Len < 0)
  646.         {
  647.             if(SysReqHandler(ReqWindow,NULL,FALSE) == -2)
  648.             {
  649.                 SetIoErr(0);
  650.  
  651.                 if(FPrintf(File,"\n") < 1)
  652.                     *Error = IoErr();
  653.  
  654.                 CloseClip();
  655.  
  656.                 return(FALSE);
  657.             }
  658.         }
  659.  
  660.         CloseClip();
  661.     }
  662.  
  663.     return(TRUE);
  664. }
  665.  
  666.     /* PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error):
  667.      *
  668.      *    Print the contents of the text buffer.
  669.      */
  670.  
  671. BYTE __regargs
  672. PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error)
  673. {
  674.     BYTE Continue = TRUE;
  675.     LONG i,Len;
  676.  
  677.     ObtainSemaphore(BufferSemaphore);
  678.  
  679.     if(BufferLines)
  680.     {
  681.         for(i = 0 ; i < Lines ; i++)
  682.         {
  683.             Len = BufferLines[i][-1];
  684.  
  685.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  686.             {
  687.                 *Error = 0;
  688.  
  689.                 Continue = FALSE;
  690.  
  691.                 break;
  692.             }
  693.  
  694.             if(Len)
  695.             {
  696.                 SetIoErr(0);
  697.  
  698.                 if(FWrite(File,BufferLines[i],Len,1) != 1)
  699.                 {
  700.                     *Error = IoErr();
  701.  
  702.                     Continue = FALSE;
  703.  
  704.                     break;
  705.                 }
  706.             }
  707.  
  708.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  709.             {
  710.                 *Error = 0;
  711.  
  712.                 Continue = FALSE;
  713.  
  714.                 break;
  715.             }
  716.  
  717.             SetIoErr(0);
  718.  
  719.             if(FPrintf(File,"\n") < 1)
  720.             {
  721.                 *Error = IoErr();
  722.  
  723.                 Continue = FALSE;
  724.  
  725.                 break;
  726.             }
  727.         }
  728.     }
  729.     else
  730.         Continue = FALSE;
  731.  
  732.     ReleaseSemaphore(BufferSemaphore);
  733.  
  734.     return(Continue);
  735. }
  736.  
  737.     /* PrintSomething(BYTE Source):
  738.      *
  739.      *    Print the screen or the current contents of the clipboard.
  740.      */
  741.  
  742. VOID __regargs
  743. PrintSomething(BYTE Source)
  744. {
  745.     struct Window        *ReqWindow;
  746.     struct EasyStruct     Easy;
  747.     LONG             Error = 0;
  748.  
  749.         /* Fill in the easy requester structure. */
  750.  
  751.     Easy . es_StructSize    = sizeof(struct EasyStruct);
  752.     Easy . es_Flags        = NULL;
  753.     Easy . es_Title        = (STRPTR)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  754.     Easy . es_GadgetFormat    = (STRPTR)LocaleString(MSG_PRINT_STOP_TXT);
  755.  
  756.     if(Source == PRINT_CLIP)
  757.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_CLIP_TXT);
  758.     else
  759.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_SCREEN_TXT);
  760.  
  761.         /* The requester is to be displayed while printing. */
  762.  
  763.     if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  764.     {
  765.         BPTR SomeFile;
  766.  
  767.             /* Add header information if printer channel is already open. */
  768.  
  769.         if(PrinterCapture)
  770.         {
  771.             if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT)) < 1)
  772.             {
  773.                 FreeSysRequest(ReqWindow);
  774.  
  775.                 ReqWindow = NULL;
  776.  
  777.                 Error = IoErr();
  778.             }
  779.             else
  780.                 SomeFile = PrinterCapture;
  781.         }
  782.         else
  783.         {
  784.                 /* Open printer channel. */
  785.  
  786.             if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  787.             {
  788.                 FreeSysRequest(ReqWindow);
  789.  
  790.                 ReqWindow = NULL;
  791.  
  792.                 Error = IoErr();
  793.             }
  794.         }
  795.  
  796.             /* Everything fine so far? */
  797.  
  798.         if(!Error)
  799.         {
  800.             BYTE Stopped;
  801.  
  802.                 /* Are we to print the screen? */
  803.  
  804.             if(Source == PRINT_SCREEN)
  805.                 Stopped = !PrintScreen(SomeFile,ReqWindow,&Error);
  806.             else
  807.                 Stopped = !PrintClip(SomeFile,ReqWindow,&Error);
  808.  
  809.                 /* Add a trailer if necessary. */
  810.  
  811.             if(PrinterCapture)
  812.             {
  813.                 if(!Error && !Stopped)
  814.                 {
  815.                     SetIoErr(0);
  816.  
  817.                     if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT)) < 1)
  818.                         Error = IoErr();
  819.                 }
  820.             }
  821.             else
  822.             {
  823.                     /* Close the printer stream. */
  824.  
  825.                 if(!Close(SomeFile))
  826.                     Error = IoErr();
  827.             }
  828.         }
  829.  
  830.             /* Release the system requster. */
  831.  
  832.         if(ReqWindow)
  833.             FreeSysRequest(ReqWindow);
  834.  
  835.             /* Display the error code if necessary. */
  836.  
  837.         if(Error)
  838.         {
  839.             STRPTR ErrorString;
  840.  
  841.             if(Fault(Error,"",SharedBuffer,256))
  842.                 ErrorString = SharedBuffer;
  843.             else
  844.                 ErrorString = "???";
  845.  
  846.             MyEasyRequest(Window,LocaleString(MSG_PRINT_ERROR_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error,ErrorString);
  847.         }
  848.     }
  849. }
  850.  
  851.     /* PrintRegion(WORD Top,WORD Bottom):
  852.      *
  853.      *    Print the contents of a screen region.
  854.      */
  855.  
  856. VOID __regargs
  857. PrintRegion(WORD Top,WORD Bottom)
  858. {
  859.     BPTR     SomeFile;
  860.     WORD     i,j;
  861.     UBYTE    *Buffer;
  862.  
  863.     if(PrinterCapture)
  864.     {
  865.         if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT)) < 1)
  866.         {
  867.             MyEasyRequest(Window,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  868.  
  869.             return;
  870.         }
  871.  
  872.         SomeFile = PrinterCapture;
  873.     }
  874.     else
  875.     {
  876.         if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  877.         {
  878.             MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  879.  
  880.             return;
  881.         }
  882.     }
  883.  
  884.     for(i = Top ; i < Bottom ; i++)
  885.     {
  886.         Buffer = &Raster[i * RasterWidth];
  887.  
  888.         j = LastColumn;
  889.  
  890.         while(j >= 0 && Buffer[j] == ' ')
  891.             j--;
  892.  
  893.         if(j >= 0)
  894.         {
  895.             SetIoErr(0);
  896.  
  897.             if(FWrite(SomeFile,Buffer,j + 1,1) < 1)
  898.                 break;
  899.         }
  900.  
  901.         SetIoErr(0);
  902.  
  903.         if(FWrite(SomeFile,"\n",1,1) < 1)
  904.             break;
  905.     }
  906.  
  907.     if(PrinterCapture)
  908.         FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT));
  909.     else
  910.         Close(SomeFile);
  911. }
  912.